package leetcode.code1508;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import leetcode.IDebug;
import leetcode.helper.H;

public class Solution2 implements IDebug {

	int mod = (int) 1e9 + 7;

	public int rangeSum(int[] nums, int n, int left, int right) {
		List<Integer> list = new ArrayList<>();
		for (int i = 0; i < nums.length; i++) {
			for (int j = i, sum = 0; j >= 0; j--) {
				sum += nums[j];
				list.add(sum);
			}
		}
		Collections.sort(list);
		long ans = 0;
		for (int i = left - 1; i < right; i++) {
			ans += list.get(i);
			ans %= mod;
		}
		return (int) ans;
	}

	@Override
	public void debug4() {
		H.compare(13, this.rangeSum(H.str2array3("[1,2,3,4]"), 4, 1, 5));

	}

	@Override
	public void debug3() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug2() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug1() {
		// TODO Auto-generated method stub

	}

	public static void main(String[] args) {
		Solution2 so = new Solution2();
		so.debug1();
		so.debug2();
		so.debug3();
		so.debug4();

	}

}
